module.exports = function ($scope, $resource, $modalInstance, platformInfo, mobile, toaster) {

	$scope.price = platformInfo.balance_price - platformInfo.block_price;
	$scope.detail = { mobile: mobile };

	//保存
	$scope.save = function() {
		if(!$scope.detail.money){
			toaster.warning({title: '', body: '金额错误'});
			return;
		}
		if($scope.detail.money < 10){
			toaster.warning({title: '', body: '提现金额最低为 10 元'});
			return;
		}
		if($scope.detail.money > $scope.price){
			toaster.warning({title: '', body: '提现金额超过可提现余额'});
			return;
		}
		if(!$scope.detail.bankcard){
			toaster.warning({title: '', body: '请填写银行卡号'});
			return;
		}
		if(!$scope.detail.bankcardname){
			toaster.warning({title: '', body: '请填写银行卡号户主姓名'});
			return;
		}
		if(!$scope.detail.vcode){
			toaster.warning({title: '', body: '请填写短信验证码'});
			return;
		}
		var para = {
			'key': $scope.detail.key,
			'vcode': $scope.detail.vcode,
			'bankcard': $scope.detail.bankcard,
			'bankname': $scope.detail.bankname,
			'bankcardname': $scope.detail.bankcardname,
			'money': $scope.detail.money
		}
		$resource('/api/ac/pc/payBmAccountService/setWithdraw', {}, {}).save(para, function(res){
			if(res.errcode === 0){
				toaster.success({title: '', body: '提现成功'});
				$modalInstance.close(para);
			} else {
				toaster.error({title: '', body: res.errmsg});
			}
		});
	}

	//发送验证码
	$scope.sendCode = function() {
		var sendBtn = $('#sendcode');
		var timeout = 59
		sendBtn.attr('disabled', true);
		sendBtn.text(timeout + 1 + ' (s)');
		$resource('/api/ac/pc/payBmAccountService/sendCodeByWithdraw', {}, {}).save({}, function(res){
			if(res.errcode === 0){
				toaster.success({title: '', body: '验证码发送成功'});
				$scope.detail.key = res.data
			} else {
				toaster.error({title: '', body: res.errmsg});
				return
			}
		});
		$scope.detail.interval = setInterval(function(){
			sendBtn.text(timeout + ' (s)');
			timeout -= 1;
			if(timeout < -1){
				clearInterval($scope.detail.interval);
				sendBtn.text('发送验证码');
				sendBtn.attr('disabled', false);
			}
		}, 1000);
	};

	//取消
	$scope.cancel = function() {
		$modalInstance.dismiss('cancel'); 
	};


};